clear all
cd "/Users/49066413/Dropbox/Dataverse_AEFIK"



**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************
*Table 1
**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************


*Firm-level summary statistics
use firm_level_data_final, clear

*Column 1, 2, and 3
tabstat tfp roc mpl emp log_emp sym_emp inv machine_inv percent_closed percent_sold, stat (N mean)

*Column 4, 5, and 6
tabstat tfp roc mpl emp log_emp sym_emp inv machine_inv percent_closed percent_sold if negative_eps==1, stat (N mean)

*Column 7, 8, and 9
tabstat tfp roc mpl emp log_emp sym_emp inv machine_inv percent_closed percent_sold if negative_eps==0, stat (N mean)


*Plant-level summary statistics
use plant_level_data_final, clear

*Column 1, 2, and 3
tabstat tfp roc mpl emp log_emp sym_emp prod_emp nonprod_emp inv machine_inv comp_inv age size, stat (N mean)

*Column 4, 5, and 6
tabstat tfp roc mpl emp log_emp sym_emp prod_emp nonprod_emp inv machine_inv comp_inv age size if negative_eps==1, stat (N mean)

*Column 7, 8, and 9
tabstat tfp roc mpl emp log_emp sym_emp prod_emp nonprod_emp inv machine_inv comp_inv age size if negative_eps==0, stat (N mean)




**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************
*Table 2
**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************

*Panel A
use firm_level_data_final, clear
 

reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)



*Panel B
use plant_level_data_final, clear
 

reghdfe change_tfp3W negative_eps size age sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( state#year ind#year) vce(cluster gvkey)




**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************
*Table 3
**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************


use plant_level_data_final, clear
 
*Panel A Column 1
reghdfe change_empW negative_eps size age sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( state#year ind#year) vce(cluster gvkey)

*Panel A Column 2
reghdfe change_invW negative_eps size age sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( state#year ind#year) vce(cluster gvkey)

*Panel A Column 3
reghdfe separation negative_eps size age sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( state#year ind#year) vce(cluster gvkey)


*Panel B Column 1
reghdfe change_machine_invW negative_eps size age sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 2
reghdfe change_comp_invW negative_eps size age sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( state#year ind#year) vce(cluster gvkey)


*Panel C Column 1
reghdfe change_prod_empW negative_eps size age sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( state#year ind#year) vce(cluster gvkey)

*Panel C Column 2
reghdfe change_nonprod_empW negative_eps size age sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( state#year ind#year) vce(cluster gvkey)



**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************
*Table 4
**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************


use plant_level_data_final, clear

*Panel A Column 1
reghdfe change_empW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age, a( state#year ind#year) vce(cluster gvkey)

*Panel A Column 2
reghdfe change_invW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age, a( state#year ind#year) vce(cluster gvkey)

*Panel A Column 3
reghdfe separation unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 1
reghdfe change_machine_invW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 2
reghdfe change_comp_invW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age, a( state#year ind#year) vce(cluster gvkey)

*Panel C Column 1
reghdfe change_prod_empW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age, a( state#year ind#year) vce(cluster gvkey)

*Panel C Column 2
reghdfe change_nonprod_empW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age, a( state#year ind#year) vce(cluster gvkey)





**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************
*Table 5
**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************
use plant_level_data_final, clear

*Panel A Column 1
reghdfe change_tfp3W unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age, a( state#year ind#year) vce(cluster gvkey)



**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************
*Table 6
**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************


use firm_level_data_final, clear

*Column 1
reghdfe change_inv1W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)

*Column 2
reghdfe change_inv2W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)

*Column 3
reghdfe change_inv3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)

*Column 4
reghdfe change_emp1W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)

*Column 5
reghdfe change_emp2W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)

*Column 6
reghdfe change_emp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)

*Column 7
reghdfe change_tfp1W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)

*Column 8
reghdfe change_tfp2W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)

*Column 9
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)




**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************
*Table 7
**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************


use firm_level_data_final, clear

*Panel A Column 1
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)

*Panel A Column 2
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft if above_med_rtw1==1, a( year) vce(cluster gvkey)

*Panel A Column 3
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft if above_med_rtw1==0, a( year) vce(cluster gvkey)

*Panel A Column 4
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft if above_med_rtw2==1, a( year) vce(cluster gvkey)

*Panel A Column 5
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft if above_med_rtw2==0, a( year) vce(cluster gvkey)


*Panel B Column 1
reghdfe change_tfp3W negative_eps emp_cut inter_table7 sue_repo_adj_prcw sue_repo_adj_prcwXleft if above_med_rtw1==1, a( year) vce(cluster gvkey)

*Panel B Column 2
reghdfe change_tfp3W negative_eps emp_cut inter_table7 sue_repo_adj_prcw sue_repo_adj_prcwXleft if above_med_rtw1==0, a( year) vce(cluster gvkey)

*Panel B Column 3
reghdfe change_tfp3W negative_eps emp_cut inter_table7 sue_repo_adj_prcw sue_repo_adj_prcwXleft if above_med_rtw2==1, a( year) vce(cluster gvkey)

*Panel B Column 4
reghdfe change_tfp3W negative_eps emp_cut inter_table7 sue_repo_adj_prcw sue_repo_adj_prcwXleft if above_med_rtw2==0, a( year) vce(cluster gvkey)


use plant_level_data_final, clear

*Panel C Column 1
reghdfe change_empW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if rtw==1, a( state#year ind#year) vce(cluster gvkey)

*Panel C Column 2
reghdfe change_invW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if rtw==1, a( state#year ind#year) vce(cluster gvkey)

*Panel C Column 3
reghdfe separation unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if rtw==1, a( state#year ind#year) vce(cluster gvkey)

*Panel C Column 4
reghdfe change_empW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if rtw==0, a( state#year ind#year) vce(cluster gvkey)

*Panel C Column 5
reghdfe change_invW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if rtw==0, a( state#year ind#year) vce(cluster gvkey)

*Panel C Column 6
reghdfe separation unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if rtw==0, a( state#year ind#year) vce(cluster gvkey)




**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************
*Table 8
**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************

use firm_level_data_final, clear

*Panel A Column 1
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft if constrained_ww==1, a( year) vce(cluster gvkey)

*Panel A Column 2
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft if constrained_ww==0, a( year) vce(cluster gvkey)

*Panel A Column 3
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft if constrained_rating==1, a( year) vce(cluster gvkey)

*Panel A Column 4
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft if constrained_rating==0, a( year) vce(cluster gvkey)


use plant_level_data_final, clear

*Panel B Column 1
reghdfe change_empW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if constrained_ww==1, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 2
reghdfe change_invW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if constrained_ww==1, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 3
reghdfe separation unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if constrained_ww==1, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 4
reghdfe change_empW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if constrained_ww==0, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 5
reghdfe change_invW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if constrained_ww==0, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 6
reghdfe separation unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if constrained_ww==0, a( state#year ind#year) vce(cluster gvkey)


*Panel C Column 1
reghdfe change_empW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if constrained_rating==1, a( state#year ind#year) vce(cluster gvkey)

*Panel C Column 2
reghdfe change_invW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if constrained_rating==1, a( state#year ind#year) vce(cluster gvkey)

*Panel C Column 3
reghdfe separation unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if constrained_rating==1, a( state#year ind#year) vce(cluster gvkey)

*Panel C Column 4
reghdfe change_empW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if constrained_rating==0, a( state#year ind#year) vce(cluster gvkey)

*Panel C Column 5
reghdfe change_invW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if constrained_rating==0, a( state#year ind#year) vce(cluster gvkey)

*Panel C Column 6
reghdfe separation unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if constrained_rating==0, a( state#year ind#year) vce(cluster gvkey)



**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************
*Table 9
**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************

use firm_level_data_final, clear

*Panel A Column 1
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)

*Panel A Column 2
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft if long_horizon==0, a( year) vce(cluster gvkey)

*Panel A Column 3
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft if long_horizon==1, a( year) vce(cluster gvkey)


use plant_level_data_final, clear

*Panel B Column 1
reghdfe change_empW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if long_horizon==0, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 2
reghdfe change_invW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if long_horizon==0, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 3
reghdfe separation unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if long_horizon==0, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 4
reghdfe change_empW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if long_horizon==1, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 5
reghdfe change_invW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if long_horizon==1, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column long_horizon
reghdfe separation unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if long_horizon==1, a( state#year ind#year) vce(cluster gvkey)




**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************
*Table 10
**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************

use firm_level_data_final, clear

*Panel A Column 1
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)

*Panel A Column 2
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft if ceo_eps==1, a( year) vce(cluster gvkey)

*Panel A Column 3
reghdfe change_tfp3W negative_eps sue_repo_adj_prcw sue_repo_adj_prcwXleft if ceo_eps==0, a( year) vce(cluster gvkey)


use plant_level_data_final, clear

*Panel B Column 1
reghdfe change_empW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if ceo_eps==1, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 2
reghdfe change_invW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if ceo_eps==1, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 3
reghdfe separation unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if ceo_eps==1, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 4
reghdfe change_empW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if ceo_eps==0, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 5
reghdfe change_invW unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if ceo_eps==0, a( state#year ind#year) vce(cluster gvkey)

*Panel B Column 6
reghdfe separation unproductive_lag inter1_table4 inter2_table4 sue_repo_adj_prcw inter3_table4 inter4_table4 inter5_table4 size age if ceo_eps==0, a( state#year ind#year) vce(cluster gvkey)




**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************
*Table 11
**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************


use firm_level_data_final, clear

*Panel A Column 1
reghdfe change_tfp3W negative_eps inv_cut_hhi inter_table12 sue_repo_adj_prcw sue_repo_adj_prcwXleft, a( year) vce(cluster gvkey)

*Panel A Column 2
reghdfe change_tfp3W negative_eps inv_cut_hhi inter_table12 sue_repo_adj_prcw sue_repo_adj_prcwXleft if high_wf_tfp_sd==0, a( year) vce(cluster gvkey)

*Panel A Column 3
reghdfe change_tfp3W negative_eps inv_cut_hhi inter_table12 sue_repo_adj_prcw sue_repo_adj_prcwXleft if high_wf_tfp_sd==1, a( year) vce(cluster gvkey)




**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************
*Figure 1
**********************************************************************************************************************************************
**********************************************************************************************************************************************
**********************************************************************************************************************************************

use firm_level_data_final, clear

cap drop bin
gen bin=0 if (sue_repo_adj_prcw>-0.0030&sue_repo_adj_prcw<=-0.0027)
replace bin=1 if (sue_repo_adj_prcw>-0.0030&sue_repo_adj_prcw<=-0.0027)
replace bin=2 if (sue_repo_adj_prcw>-0.0027&sue_repo_adj_prcw<=-0.0024)
replace bin=3 if (sue_repo_adj_prcw>-0.0024&sue_repo_adj_prcw<=-0.0021)
replace bin=4 if (sue_repo_adj_prcw>-0.0021&sue_repo_adj_prcw<=-0.0018)
replace bin=5 if (sue_repo_adj_prcw>-0.0018&sue_repo_adj_prcw<=-0.0015)
replace bin=6 if (sue_repo_adj_prcw>-0.0015&sue_repo_adj_prcw<=-0.0012)
replace bin=7 if (sue_repo_adj_prcw>-0.0012&sue_repo_adj_prcw<=-0.0009)
replace bin=8 if (sue_repo_adj_prcw>-0.0009&sue_repo_adj_prcw<=-0.0006)
replace bin=9 if (sue_repo_adj_prcw>-0.0006&sue_repo_adj_prcw<=-0.0003)
replace bin=10 if (sue_repo_adj_prcw>-0.0003&sue_repo_adj_prcw<=0.0000)
replace bin=11 if (sue_repo_adj_prcw>0.0000&sue_repo_adj_prcw<=0.0003)
replace bin=12 if (sue_repo_adj_prcw>0.0003&sue_repo_adj_prcw<=0.0006)
replace bin=13 if (sue_repo_adj_prcw>0.0006&sue_repo_adj_prcw<=0.0009)
replace bin=14 if (sue_repo_adj_prcw>0.0009&sue_repo_adj_prcw<=0.0012)
replace bin=15 if (sue_repo_adj_prcw>0.0012&sue_repo_adj_prcw<=0.0015)
replace bin=16 if (sue_repo_adj_prcw>0.0015&sue_repo_adj_prcw<=0.0018)
replace bin=17 if (sue_repo_adj_prcw>0.0018&sue_repo_adj_prcw<=0.0021)
replace bin=18 if (sue_repo_adj_prcw>0.0021&sue_repo_adj_prcw<=0.0024)
replace bin=19 if (sue_repo_adj_prcw>0.0024&sue_repo_adj_prcw<=0.0027)
replace bin=20 if (sue_repo_adj_prcw>0.0027&sue_repo_adj_prcw<=0.0030)

cap drop mean_tfp
egen mean_tfp=mean(change_tfp3W), by(bin)

plot mean_tfp bin


